package com.controller;

import com.constant.ResultCodeConstant;
import com.dto.ActivityDTO;
import com.model.ActivityDO;
import com.query.ActivityQuery;
import com.rest.RestResult;
import com.service.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   活动信息管理控制器
 * </p>
 * @author 34448
 */
@Api(tags = "活动信息管理")
@RequestMapping("/activity")
@RestController
public class ActivityController {

    @Autowired
    private ActivityService activityService;

    /**
     * 发布活动
     *
     * @param activityDTO 活动信息
     * @return
     */
    @PostMapping("/publish")
    @ApiOperation("发布活动")
    public RestResult<Boolean> publishActivity(@RequestBody @Validated ActivityDTO activityDTO) {
        Boolean result = activityService.publishActivity(activityDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 更新活动
     *
     * @param activityDTO 活动信息
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("更新活动")
    public RestResult<Boolean> updateActivity(@RequestBody @Validated ActivityDTO activityDTO) {
        Boolean result = activityService.updateActivity(activityDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 取消活动
     *
     * @param activityQuery 活动查询条件
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消活动")
    public RestResult<Boolean> cancelActivity(@RequestBody @Validated ActivityQuery activityQuery) {
        Boolean result = activityService.cancelActivity(activityQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查看活动
     *
     * @param activityQuery 活动查询条件
     * @return
     */
    @GetMapping("/info")
    @ApiOperation("查看活动")
    public RestResult<List<ActivityDO>> getActivityInfo(@Validated ActivityQuery activityQuery) {
        List<ActivityDO> result = activityService.getActivityList(activityQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}